<script setup lang="ts">
import { Question } from '@/api/subject/type';
import { showToast } from 'vant';
import { ref } from 'vue';

const question = ref({} as Question);
const judge = ref('true');
const emit = defineEmits(["submit"]);
const submit = () => {
    question.value.type = 'Judge';
    question.value.answer = JSON.stringify({
        correctAnswer: judge.value
    });
    if (!question.value.title || !question.value.title.trim()) {
    showToast('题目描述不能为空');
    return;
  }
    emit('submit', question.value);
}
</script>

<template>
    <div class="form">
        <van-field v-model="question.title" label="题目描述" type="textarea" rows="3" placeholder="请输入题目描述" />
        <van-field name="judge" label="答案">
            <template #input>
                <van-radio-group v-model="judge" direction="horizontal">
                    <van-radio name="true">正确</van-radio>
                    <van-radio name="false">错误</van-radio>
                </van-radio-group>
            </template>
        </van-field>
        <div class="submit">
            <van-button type="primary" block @click="submit">提交</van-button>
        </div>
    </div>
</template>

<style lang="scss" scoped>
.submit {
    margin-top: 24px;
}
</style>